package com.itcast.controller;

import com.alibaba.fastjson.JSONArray;
import com.itcast.bean.Location.reqUserLocation.request.LocationRequestBean;
import com.itcast.bean.Location.requestNearbyLocation.request.RequestNearbyLocationBean;
import com.itcast.service.LocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
@Controller
@RequestMapping("/location")
public class LocationController extends BaseController {

    @Autowired
    LocationService locationService;

    @RequestMapping(value = "/reqUserLocation",method = {RequestMethod.GET,RequestMethod.POST},consumes = "application/json")
    @ResponseBody
    public String reqUserLocation(HttpServletRequest request, @RequestBody LocationRequestBean locationRequestBean){

        String respBody= JSONArray.toJSONString(locationService.requestUserLocation(locationRequestBean));           //此处每次需要手动将相应字符串设置到某个位置(此处为request中)，然后在拦截器里面统一打印出来，有什么办法可以优化，不用反复谢这个代码
        request.setAttribute(RESPONSEKEY,respBody);
        return respBody;
    }

    @RequestMapping(value = "/requestNearbyLocation",method = {RequestMethod.GET,RequestMethod.POST},consumes = "application/json")
    @ResponseBody
    public String requestNearbyLocation(HttpServletRequest request, @RequestBody RequestNearbyLocationBean requestNearbyLocationBean){

        String respBody= JSONArray.toJSONString(locationService.requestNearbyLocation(requestNearbyLocationBean));           //此处每次需要手动将相应字符串设置到某个位置(此处为request中)，然后在拦截器里面统一打印出来，有什么办法可以优化，不用反复谢这个代码
        request.setAttribute(RESPONSEKEY,respBody);
        return respBody;
    }
}
